﻿//#version 150

in vec3 passNormal;
in vec2 passTexCoord;

uniform sampler2D textureMap;
uniform vec3 diffuseColor;
uniform bool transparent = false;
uniform bool textureExists = true;

out vec4 outColor;

const vec3 lihtDirection = vec3(0, 0, 1);

void main() {
    if (transparent) {
        if (int(gl_FragCoord.x + gl_FragCoord.y) % 2 == 1) discard;
    }

    if ((!textureExists) || passTexCoord == vec2(-1, -1)) { // when texture coordinate not exists..
        float diffuse = max(dot(normalize(lihtDirection), normalize(passNormal)), 0);
        outColor = vec4(diffuseColor * diffuse, 1.0);
    }
    else {
        outColor = texture(textureMap, passTexCoord);
    }
}